#!/bin/bash

# 备份原文件
cp CodeBlocks_wx32_64.cbp CodeBlocks_wx32_64.cbp.backup

# 查找插件单元列表的结束位置（在最后一个插件文件之后）
last_plugin_line=$(grep -n 'filename="plugins/' CodeBlocks_wx32_64.cbp | tail -1 | cut -d: -f1)

if [ -n "$last_plugin_line" ]; then
    # 在最后一个插件文件后插入新的配置管理器插件文件
    sed -i "${last_plugin_line}a\\
\t\t<Unit filename=\"plugins/configmanager_common/include/configmanager.h\" />\\
\t\t<Unit filename=\"plugins/configmanager_common/src/configmanager.cpp\" />\\
\t\t<Unit filename=\"plugins/configmanager_common/include/configurationpanel.h\" />\\
\t\t<Unit filename=\"plugins/configmanager_common/src/configurationpanel.cpp\" />\\
\t\t<Unit filename=\"plugins/configmanager_importers/include/importers_globals.h\" />\\
\t\t<Unit filename=\"plugins/configmanager_importers/src/importers_globals.cpp\" />\\
\t\t<Unit filename=\"plugins/configmanager_exporters/include/exporters_globals.h\" />\\
\t\t<Unit filename=\"plugins/configmanager_exporters/src/exporters_globals.cpp\" />" CodeBlocks_wx32_64.cbp
fi

echo "CodeBlocks_wx32_64.cbp 更新完成"
